from rest_framework.generics import ListAPIView,CreateAPIView
from meiduo_admin.serializers.user_serializers import UserSerialzer
from meiduo_admin.pages import MyPage
from users.models import User

class UserView(ListAPIView,CreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerialzer
    pagination_class = MyPage

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword is None or keyword is "":
            return User.objects.all()
        else:
            return self.queryset.filter(username__contains=keyword)
